﻿using System;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
using System.Web.UI.WebControls;
using System.Web.UI;
using System.Data;
using System.IO;

namespace EnhancedSolutions.Layouts.EnhancedSolutions
{
    public partial class DisposeCheckResult : LayoutsPageBase
    {
        protected void Page_Load(object sender, EventArgs e)
        {

            if (Session["DisposeResult"] != null)
            {
                DisposeResultList resultList = (DisposeResultList)Session["DisposeResult"];
                DataSet data = new DataSet();
                foreach (DisposeResult item in resultList)
                {
                    DataSet temp = new DataSet();
                    temp.ReadXml(new StringReader(item.Message.OuterXml));
                    data.Merge(temp);
                }
                Control control;
                if (data.Tables.Count == 0)
                {
                    Label l1 = new Label();
                    l1.Text = "No dispose errors/warnings were found.";
                    control = l1;
                }
                else
                {
                    data.Tables[0].Columns.RemoveAt(0);
                    GridView grid = new GridView();
                    grid.DataSource = data;
                    grid.DataBind();
                    
                    control = grid;
                }
                    DisposeResultsPlaceHolder.Controls.Add(control);
                    DisposeResultsPlaceHolder.Controls.Add(new LiteralControl("<br />"));
            }
        }
    }
}
